`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    02:00:28 04/08/2014 
// Design Name: 
// Module Name:    scoring 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module scoring(clk_1KHz, rand1, rand2, rand3, rand4, 
	            rand5, rand6, rand7, rand8,
	            rand9, rand10, rand11, rand12,
	            rand13, rand14, rand15, rand16,
               M1, M2, M3, M4,
		         M5, M6, M7, M8, 
		         M9, M10, M11, M12, 
		         M13, M14, M15, M16,
					button, column, score, wrong);

	 input clk_1KHz;
	 input [3:0] rand1, rand2, rand3, rand4;
	 input [3:0] rand5, rand6, rand7, rand8;
	 input [3:0] rand9, rand10, rand11, rand12;
	 input [3:0] rand13, rand14, rand15, rand16;
	 input [9:0] M1, M2, M3, M4;
	 input [9:0] M5, M6, M7, M8;
	 input [9:0] M9, M10, M11, M12;
	 input [9:0] M13, M14, M15, M16;

	 
	 input button;
	 input [2:0] column;
	 output reg score;
	 output reg wrong;
	 
	always @(posedge clk_1KHz) begin
//right parts
//	M1-M4 right part

		if(M1>=400 && M1<=463) begin
			if(button==1 && rand1[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;				
			end
		end
		
		if(M2>=400 && M2<=463) begin
			if(button==1 && rand2[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
		
		if(M3>=400 && M3<=463) begin
			if(button==1 && rand3[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
		
		if(M4>=400 && M4<=463) begin
			if(button==1 && rand4[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
//	M5-M8 right part
		if(M5>=400 && M5<=463) begin
			if(button==1 && rand5[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;				
			end
		end
		
		if(M6>=400 && M6<=463) begin
			if(button==1 && rand6[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
		
		if(M7>=400 && M7<=463) begin
			if(button==1 && rand7[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
		
		if(M8>=400 && M8<=463) begin
			if(button==1 && rand8[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
//	M9-M12 right part
		if(M9>=400 && M9<=463) begin
			if(button==1 && rand9[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;				
			end
		end
		
		if(M10>=400 && M10<=463) begin
			if(button==1 && rand10[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
		
		if(M11>=400 && M11<=463) begin
			if(button==1 && rand11[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
		
		if(M12>=400 && M12<=463) begin
			if(button==1 && rand12[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
//	M13-M16 right part
		if(M13>=400 && M13<=463) begin
			if(button==1 && rand13[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;				
			end
		end
		
		if(M14>=400 && M14<=463) begin
			if(button==1 && rand14[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
		
		if(M15>=400 && M15<=463) begin
			if(button==1 && rand15[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end
		
		if(M16>=400 && M16<=463) begin
			if(button==1 && rand16[column]==1)begin
				score = 1;
				wrong = 0;
			end else begin
				score = 0;
			end
		end

//wrong parts
// M1-M4 wrong part
		if(M1>=400 && M1<=463) begin
			if((button==1) && ~(rand1[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;				
			end
		end
		
		if(M2>=400 && M2<=463) begin
			if((button==1) && ~(rand2[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
		
		if(M3>=400 && M3<=463) begin
			if((button==1) && ~(rand3[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
		
		if(M4>=400 && M4<=463) begin
			if((button==1) && ~(rand4[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
// M5-M8 wrong part
		if(M5>=400 && M5<=463) begin
			if((button==1) && ~(rand5[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;				
			end
		end
		
		if(M6>=400 && M6<=463) begin
			if((button==1) && ~(rand6[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
		
		if(M7>=400 && M7<=463) begin
			if((button==1) && ~(rand7[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
		
		if(M8>=400 && M8<=463) begin
			if((button==1)&& ~(rand8[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
// M9-M12 wrong part
		if(M9>=400 && M9<=463) begin
			if((button==1)&& ~(rand9[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;				
			end
		end
		
		if(M10>=400 && M10<=463) begin
			if((button==1)&& ~(rand10[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
		
		if(M11>=400 && M11<=463) begin
			if((button==1) && ~(rand11[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
		
		if(M12>=400 && M12<=463) begin
			if((button==1) && ~(rand12[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
// M13-M16 wrong part
		if(M13>=400 && M13<=463) begin
			if((button==1) && ~(rand13[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;				
			end
		end
		
		if(M14>=400 && M14<=463) begin
			if((button==1) && ~(rand14[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
		
		if(M15>=400 && M15<=463) begin
			if((button==1) && ~(rand15[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end
		
		if(M16>=400 && M16<=463) begin
			if((button==1)&& ~(rand16[column]==1))begin
				wrong = 1;
			end else begin
				wrong = 0;
			end
		end

	end
endmodule